class A_PERMUTE{ETP,ATP<$ARR{ETP}}
****
Permutation algorithms - a bit bare right now. Usage:
_____src:_ARRAY{INT}_:=_|1,2,5|;
_____p:_FLIST{INT}_:=_#(|2,1,0|);
_____dest:_ARRAY{INT}_:=_#(3);
_____i.e._first_element_of_"src"_s[0]=1_goes_to_dest[2]
__________2nd_elt_of_src_(2)_goes_to_dest[1]
__________3rd_elt_of_src_(5)_goes_to_dest[0]
_____perm_alg:_A_PERMUTE{INT,ARRAY{INT}};
_____perm_alg.permute_into(src,p,dest);
_____Should_permute_src_into_|5,2,1|;


Flattened version is here

Ancestors
COMPARE{_}



Public


Features
permute_into(src:ATP,new_pos:$ARR{INT},dest:ATP)
**** Copy the entries from src into dest using the permutation array "new_positions" src[i] -> dest[new_pos[i]] Look at new_pos as a mapping from domain indices to range indices
_____src:_ARRAY{INT}_:=_|1,2,5|;
_____p:_FLIST{INT}_:=_#(|2,1,0|);
_____dest:_ARRAY{INT}_:=_#(3);
_____i.e._first_element_of_"src"_s[0]=1_goes_to_dest[2]
__________2nd_elt_of_src_(2)_goes_to_dest[1]
__________3rd_elt_of_src_(5)_goes_to_dest[0]
_____permute_into(src,p,dest);__--_____Destination=_|5,2,1|;
shuffle(a:ATP)
**** Shuffle the elements of self. This is a trivial, obvious implementation, but not sure if it is sufficient for good randomness
sorted_is_permutation(p1,p2: ATP): BOOL
**** Inputs must be sorted True if p1 is a permutation of p2. Requires self and p2 to both be pre-sorted
to_reverse(a:ATP)
**** Reverse the order of the elements in self. Self may be void.


Private

is_sorted(a: ATP): BOOL
valid_ind(dest: ATP,i: INT): BOOL

The Sather Home Page